<?php
/**
 * 用户等级管理
 */
namespace app\admin\model;
use app\common\model\MemberLevel as MemberLevelModel;
class MemberLevel extends MemberLevelModel
{
    public static function getList($order,$limit = 20,$page = 1){
        $data = self::order($order)->paginate(['list_rows'=>$limit,'page'=>$page])->toArray();
        $res = [];
        foreach ($data['data'] as $k => $v){

            $upgrade = '';  //升级条件
            if($v['matrix'] == 1) $upgrade.='需要完成矩阵 | ';

            if($v['pay_mining'] == 1) $upgrade.='需要购买矿机 | ';

            //开启等级购买
            if($v['shop_pay'] == 1){
                $upgrade.= $upgrade ?'支付USDT:'.$v['pay_amount'].' | ' : '支付USDT:'.$v['pay_amount'];
            }

            //开启直推条件
            if($v['push'] == 1){
                $upgrade.='直推人数:'.$v['push_num'];
                if($v['push_level'] > 0){
                    $push_level = self::getLevelDetails($v['push_level']);
                    if(!empty($push_level)) $upgrade.= ' | 直推用户等级:'.$push_level['name'];
                }
            }
            //开启间推条件
            if($v['interposition'] == 1){
                $upgrade.='间推人数:'.$v['interposition_num'];
                if($v['interposition_level'] > 0){
                    $interposition_level = self::getLevelDetails($v['interposition_level']);
                    if(!empty($interposition_level)) $upgrade.= ' | 直推用户等级:'.$interposition_level['name'];
                }
                $upgrade.= ' | ';
            }
            //开启团队条件
            if($v['team'] == 1){
                $upgrade.='团队人数:'.$v['team_num'];
                if($v['team_thread'] > 0){
                    $upgrade.= ' | 团队多线程';
                }
                if($v['team_level'] > 0){
                    $team_level = self::getLevelDetails($v['team_level']);
                    if(!empty($team_level)) $upgrade.= ' | 团队用户等级:'.$team_level['name'];
                }
                $upgrade.= ' | ';
            }

            //开启团队算力
            if($v['team_computing'] > 0) $upgrade.='团队算力:'.$v['team_computing'];

            $custom = '';
            if($v['draw'] > 0) $custom.= '奖励抽奖:'.$v['draw'].'次 | ';
            if($v['weighted_dividend'] > 0) $custom.= '全网加权分红:'.$v['weighted_dividend'].'% | ';
            if($v['mining_range'] > 0) $custom.= '矿机极差奖励:'.$v['mining_range'].'%';
            if($v['power'] > 0) $custom.= '等级算力:'.$v['power'];

            $res[$k]=[
                'id'    =>  $v['id'],
                'name'  =>  $v['name'],
                'level' =>  $v['level'],
                'upgrade'   =>  $upgrade,
                'custom'    =>  $custom,
                'weighted_dividend' =>  $v['weighted_dividend'].'%',
                'draw'  =>  $v['draw'],
                'mining_range'  =>  $v['mining_range'].'%',
                'matrix_team'   =>  $v['matrix_team'] ? $v['matrix_team'].'%' : 0,
                'update_time'  =>  $v['update_time']
            ];
        }
        $data['data'] = $res;
        return $data;
    }
}